WARNING: This program has a bug, which means we need to fix it!

RULE: We need to use the keyword global followed by the name of the variable that we would like to use inside of the event. We only need to use global for variables that were created earlier in the program, outside of the event.

  • Click Run and click on the pig. Read the error message.
  • Use a Global Variable in the event so that 1 is added to clicks and the click_count display updates.

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("barn") sprite = codesters.Sprite("pig", 125, -125) clicks = 0 click_count = codesters.Display(clicks) def click(sprite): clicks += 1 click_count.update(clicks) sprite.event_click(click)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)